package util;

import models.SiteConfig;

import com.harrison.lee.twitpic4j.TwitPic;
import com.harrison.lee.twitpic4j.TwitPicResponse;

public class TwitPicCommand {
	public static TwitPicCommand newInstance() {
		return new TwitPicCommand();
	}

	private byte[] media;

	private String username;

	private String password;

	private String message;

	private TwitPicCommand() {
		SiteConfig siteConfig = SiteConfig.load();

		username = siteConfig.getConfig("twitter.pubuser");
		password = siteConfig.getConfig("twitter.pubuser.password");
	}

	public TwitPicCommand setMedia(byte[] mediaData) {
		this.media = mediaData;

		return this;
	}

	public TwitPicCommand setMessage(String message) {
		this.message = message;

		return this;
	}

	public boolean send() throws Exception {
		TwitPic twitPic = new TwitPic(username, password);
		
		TwitPicResponse response = twitPic.uploadAndPost(media, message);
		
		return "ok".equals(response.getStatus());
	}
}
